﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing.plaf.basic {
    import org.aswing.*;
    import org.aswing.geom.*;
    import org.aswing.plaf.*;
    import org.aswing.event.*;

    public class BasicScrollPaneUI extends BaseComponentUI {

        protected var scrollPane:JScrollPane;
        protected var lastViewport:Viewportable;

        override public function installUI(_arg1:Component):void{
            this.scrollPane = JScrollPane(_arg1);
            this.installDefaults();
            this.installComponents();
            this.installListeners();
        }
        override public function uninstallUI(_arg1:Component):void{
            this.scrollPane = JScrollPane(_arg1);
            this.uninstallDefaults();
            this.uninstallComponents();
            this.uninstallListeners();
        }
        protected function getPropertyPrefix():String{
            return ("ScrollPane.");
        }
        private function installDefaults():void{
            var _local1:String = this.getPropertyPrefix();
            LookAndFeel.installColorsAndFont(this.scrollPane, _local1);
            LookAndFeel.installBorderAndBFDecorators(this.scrollPane, _local1);
            LookAndFeel.installBasicProperties(this.scrollPane, _local1);
            if (!this.scrollPane.getVerticalScrollBar().isFocusableSet()){
                this.scrollPane.getVerticalScrollBar().setFocusable(false);
                this.scrollPane.getVerticalScrollBar().setFocusableSet(false);
            };
            if (!this.scrollPane.getHorizontalScrollBar().isFocusableSet()){
                this.scrollPane.getHorizontalScrollBar().setFocusable(false);
                this.scrollPane.getHorizontalScrollBar().setFocusableSet(false);
            };
        }
        private function uninstallDefaults():void{
            LookAndFeel.uninstallBorderAndBFDecorators(this.scrollPane);
        }
        private function installComponents():void{
        }
        private function uninstallComponents():void{
        }
        private function installListeners():void{
            this.scrollPane.addAdjustmentListener(this.__adjustChanged);
            this.scrollPane.addEventListener(ScrollPaneEvent.VIEWPORT_CHANGED, this.__viewportChanged);
            this.__viewportChanged(null);
        }
        private function uninstallListeners():void{
            this.scrollPane.removeAdjustmentListener(this.__adjustChanged);
            this.scrollPane.removeEventListener(ScrollPaneEvent.VIEWPORT_CHANGED, this.__viewportChanged);
            if (this.lastViewport != null){
                this.lastViewport.removeStateListener(this.__viewportStateChanged);
            };
        }
        private function syncScrollPaneWithViewport():void{
            var _local4:IntDimension;
            var _local5:IntDimension;
            var _local6:IntPoint;
            var _local7:int;
            var _local8:int;
            var _local9:int;
            var _local1:Viewportable = this.scrollPane.getViewport();
            var _local2:JScrollBar = this.scrollPane.getVerticalScrollBar();
            var _local3:JScrollBar = this.scrollPane.getHorizontalScrollBar();
            if (_local1 != null){
                _local4 = _local1.getExtentSize();
                if ((((_local4.width <= 0)) || ((_local4.height <= 0)))){
                    return;
                };
                _local5 = _local1.getViewSize();
                _local6 = _local1.getViewPosition();
                if (_local2 != null){
                    _local7 = _local4.height;
                    _local8 = _local5.height;
                    _local9 = Math.max(0, Math.min(_local6.y, (_local8 - _local7)));
                    _local2.setValues(_local9, _local7, 0, _local8);
                    _local2.setUnitIncrement(_local1.getVerticalUnitIncrement());
                    _local2.setBlockIncrement(_local1.getVerticalBlockIncrement());
                };
                if (_local3 != null){
                    _local7 = _local4.width;
                    _local8 = _local5.width;
                    _local9 = Math.max(0, Math.min(_local6.x, (_local8 - _local7)));
                    _local3.setValues(_local9, _local7, 0, _local8);
                    _local3.setUnitIncrement(_local1.getHorizontalUnitIncrement());
                    _local3.setBlockIncrement(_local1.getHorizontalBlockIncrement());
                };
            };
        }
        private function __viewportChanged(_arg1:ScrollPaneEvent):void{
            if (this.lastViewport != null){
                this.lastViewport.removeStateListener(this.__viewportStateChanged);
            };
            this.lastViewport = this.scrollPane.getViewport();
            this.lastViewport.addStateListener(this.__viewportStateChanged);
        }
        private function __viewportStateChanged(_arg1:InteractiveEvent):void{
            this.syncScrollPaneWithViewport();
        }
        private function __adjustChanged(_arg1:ScrollPaneEvent):void{
            var _local2:Viewportable = this.scrollPane.getViewport();
            _local2.scrollRectToVisible(this.scrollPane.getVisibleRect(), _arg1.isProgrammatic());
        }

    }
}//package org.aswing.plaf.basic 
